package com.hzhk.happyrent.ui.fragment.home;

import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hzhk.happyrent.R;
import com.hzhk.happyrent.ui.adapter.card.CardLoadAdapter;
import com.hzhk.happyrent.ui.adapter.rent.RentLoadAdapter;
import com.hzhk.happyrent.ui.fragment.BaseFragment;
import com.hzhk.happyrent.ui.view.listview.MaiTianListview;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * User: hzhk(1097282555@qq.com)
 * Date: 2017/11/21
 * Time: 18:02
 * progject: HappyRent
 * Describe： ${Describe}
 */
public class CardFragment extends BaseFragment implements  MaiTianListview.OnMaiTianPullDownRefreshListener{

    @BindView(R.id.activity_titlebar_left)
    ImageView activityTitlebarLeft;
    @BindView(R.id.activity_titlebar_center)
    TextView activityTitlebarCenter;
    @BindView(R.id.activity_titlebar_right)
    ImageView activityTitlebarRight;
    @BindView(R.id.lv_fragment_card)
    MaiTianListview lvFragmentCard;
    private View mFragmentView;
    private CardLoadAdapter cardLoadAdapter;
    private Logger log = LoggerFactory.getLogger(this.getClass().getName());
    @Override
    protected View getContentView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_card, null);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        if (null == mFragmentView) {
            mFragmentView = super.onCreateView(inflater, container, savedInstanceState);
            log.debug("jump into onCreateView");
            initView();
            initData();
            log.debug("jump out onCreateView");
        }
        return mFragmentView;
    }

    private void initData() {
        log.debug("jump into initData");
        cardLoadAdapter = new CardLoadAdapter(getContext());
        lvFragmentCard.setAdapter(cardLoadAdapter);
        log.debug("jump out initData");
    }

    private void initView() {
        log.debug("jump into initView");
        activityTitlebarLeft.setVisibility(View.GONE);
        activityTitlebarRight.setVisibility(View.GONE);
        lvFragmentCard.setOnMaiTianRefreshListener(this);
        lvFragmentCard.setPullLoadEnable(false);
        log.debug("jump out initView");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (null != mFragmentView) {
            ((ViewGroup) mFragmentView.getParent()).removeView(mFragmentView);
        }
    }

    @OnClick(R.id.activity_titlebar_right)
    public void onViewClicked() {
    }

    @Override
    public void onRefresh() {
        lvFragmentCard.setAdapter(cardLoadAdapter);
        lvFragmentCard.stopRefresh();
    }
}
